package com.gjm.tool.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 邮件发送工具类
 */
@Service
public class MailService {

    @Resource
    private JavaMailSender mailSender;
    @Value("${spring.mail.username:15652957971@163.com}")
    private String fromMail;

    /**
     * 发送邮件
     * @param targetEmail 目标邮箱
     * @param subject
     * @param content
     */
    public void send(String targetEmail, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromMail);
        message.setTo(targetEmail);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);
    }
}
